
#ifndef __XF_TOOL_H
#define __XF_TOOL_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <assert.h>
#include <termios.h>

static struct termios stored_settings;

static void xf_echo_off(void)
{
     struct termios new_settings;
     tcgetattr(0,&stored_settings);
     new_settings = stored_settings;
     new_settings.c_lflag &= (~ECHO);
     new_settings.c_lflag &= (~ICANON);
     new_settings.c_cc[VMIN] = 1;
     tcsetattr(0,TCSANOW,&new_settings);
     return;
}

static void xf_echo_on(void)
{
     tcsetattr(0,TCSANOW,&stored_settings);
     return;
}

static char xf_getchar_noecho1(void)
{
     char c;
     xf_echo_off();
     c = getchar();
     xf_echo_on();
     return c;
}

static void print_bytes(void *ptr, int nr)
{
     int i;

     for (i = 0; i < nr; i++)
	  printf("%.2X ", ((unsigned char *)ptr)[i]);
}

#endif
